<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">

<head th:include="common">
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<table id="table"></table>
<button class="btn btn-primary btn-lg" onclick="add()" data-toggle="modal" data-target="#myModal">
    新增
</button>



<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    新增
                </h4>
            </div>
            <div class="modal-body">
                <form method="post" class="form-horizontal"  role="form" id="myForm" >
                    <div class="form-group" >
                        <label for="firstname" class="col-sm-2 control-label">优惠名称</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" name="tickName">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="lastname" class="col-sm-2 control-label">优惠力度</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" name="tickNum">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="firstname" class="col-sm-2 control-label">开始时间</label>
                        <div class="col-sm-10">
                            <input type="date" class="form-control" name="startTime" >

                        </div>
                    </div>
                    <div class="form-group">
                        <label for="lastname" class="col-sm-2 control-label">过期时间</label>
                        <div class="col-sm-10">
                            <input type="date" class="form-control" name="endTime">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="lastname" class="col-sm-2 control-label">创建时间</label>
                        <div class="col-sm-10">
                            <input type="date" class="form-control" name="createTime">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="lastname" class="col-sm-2 control-label">总票数</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" name="totalCount">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="lastname" class="col-sm-2 control-label">剩余票数</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" name="remainCount">
                        </div>
                    </div>

            </form>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">关闭
            </button>
            <button type="button" class="btn btn-primary" onclick="submitForm()">
                提交更改
            </button>
        </div>
    </div><!-- /.modal-content -->
</div><!-- /.modal -->
</div>



</body>
<script type="text/javascript">


    function submitForm(){
        $.ajax({
            url:"../coupon/add",
            data:$("#myForm").serialize(),
            success:function(){
                alert("新增成功");
                $("#table").bootstrapTable('refresh');//成功后刷新表格
                $("#myModal").modal('hide');
            }
        })
    }











    $("#table").bootstrapTable({
        url:"../coupon/couponList",
        columns:[
            {field:'tickId',title:'id'},
            {field:'tickName',title:'优惠名称'},
            {field:'tickNum',title:'力度'},
            {field:'startTime',title:'开始时间'},
            {field:'endTime',title:'过期时间'},
            {field:'createTime',title:'创建时间'},
            {field:'totalCount',title:'总票数'},
            {field:'remainCount',title:'剩余票数'},
            {field:'caozuo',title:'操作',
                formatter:function (value,row,index){
                    return '<a href="javascript:deleteCoupon('+row.tickId+')">删除</a>'
                }
            },

        ],
        pagination:true,
        pageSize:2,
        pageList:[2,4,6,8,10],
        sidePagination : 'client',//server:服务器端分页{rows:[],total:10}|client
//：前端分页 [{},{}]
    })
    //删除
    function deleteCoupon(id){
        $.ajax({
            url:"/coupon/deleteCoupon",
            data:{id:id},
            success:function(){
                $('#table').bootstrapTable('refresh');
            }
        })
    }
</script>
</html>